package com.onion.auth.context;

import com.alibaba.fastjson.JSONObject;
import com.onion.auth.handler.PostHandler;

import java.util.Stack;

public abstract class AclContext implements java.io.Serializable{

    //请求Token
    private String requestToken;
    //请求资源
    private String requestResource;
    //请求参数
    private JSONObject requestParams = new JSONObject();
    //后处理器
    private Stack<PostHandler> postHandlerStack = new Stack<>();

    public String getRequestToken() {
        return requestToken;
    }
    public void setRequestToken(String requestToken) {
        this.requestToken = requestToken;
    }

    public String getRequestResource() {
        return requestResource;
    }
    public void setRequestResource(String requestResource) {
        this.requestResource = requestResource;
    }

    public JSONObject getRequestParams() {
        return requestParams;
    }
    public void setRequestParams(JSONObject requestParams) {
        this.requestParams = requestParams;
    }
    public JSONObject pushRequestParam(String name, Object value){
        if(requestParams == null){
            this.requestParams = new JSONObject();
        }
        requestParams.put(name, value);
        return this.requestParams;
    }
    public Object getRequestParam(String name){
        return requestParams.get(name);
    }

    public Stack<PostHandler> getPostHandlerStack() {
        return postHandlerStack;
    }
    public void setPostHandlerStack(Stack<PostHandler> postHandlerStack) {
        this.postHandlerStack = postHandlerStack;
    }
    public void pushPostHandler(PostHandler postHandler){
        postHandlerStack.push(postHandler);
    }
    public PostHandler popPostHandler(){
        if(!postHandlerStack.isEmpty()){
            return postHandlerStack.pop();
        }else{
            return null;
        }
    }

}